<template>
  <page-header-wrapper>
    <page-tab-list></page-tab-list>
    <a-card :bordered="false">
      <a-form-model-item label="绑定微信小程序" :labelCol="{ span: 4 }" :wrapperCol="{ span: 16 }">
        <span v-if="status.wx_status == -1">小程序创建未完成</span>
        <a-button type="primary" v-if="status.wx_status == 0" @click="bandMini('weixin')">绑定</a-button>
        <a-button type="primary" v-if="status.wx_status == 1" disabled>已绑定</a-button>
      </a-form-model-item>
      <a-form-model-item label="绑定支付宝小程序" :labelCol="{ span: 4 }" :wrapperCol="{ span: 16 }">
        <span v-if="status.ali_status == -1">小程序创建未完成</span>
        <a-button type="primary" v-if="status.ali_status == 0" @click="bandMini('weixin')">绑定</a-button>
        <a-button type="primary" v-if="status.ali_status == 1" disabled>已绑定</a-button>
      </a-form-model-item>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getBandStatus, bandMini } from '@/api/setting/applet'

export default {
  data() {
    return {
      status: {},
    }
  },
  methods: {
    // 获取绑定状态
    async getBandStatus() {
      const hide = this.$message.loading('加载中', 0)
      const res = await getBandStatus()
      if (res.code == 0) {
        this.status = res.data
      }
      hide()
    },
    async bandMini(type) {
      const res = await bandMini({ type })
      if (res.code == 0) {
        this.$message.success('绑定成功')
        this.getBandStatus()
      }
    },
  },
  mounted() {
    this.getBandStatus()
  },
}
</script>

<style lang="less" scoped>
</style>